﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BacklogParser.WinForms
{
    public partial class Form1 : Form
    {
        private string FolderPath { get; set; }

        public Form1()
        {
            InitializeComponent();
        }

        private void BtnParse_Click(object sender, EventArgs e)
        {
            if(string.IsNullOrEmpty(this.FolderPath))
            {
                var result = MessageBox.Show("Select the folder with the backlog XML files first!", "Select folder", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                if(result == DialogResult.OK)
                {
                    this.OpenFolderBrowser();
                }
                return;
            }
            var engine = new Engine();

            var files = Directory.GetFiles(this.FolderPath).ToList();

            files = files.Where(x => x.EndsWith(".xml")).ToList();

            var paths = new List<string>();

            engine.Run(files, this.FolderPath);
        }

        private void BtnSelectFolder_Click(object sender, EventArgs e)
        {
            this.OpenFolderBrowser();
        }

        private void OpenFolderBrowser()
        {
            var folderBrowserDialog1 = new FolderBrowserDialog();
            DialogResult result = folderBrowserDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                this.FolderPath = folderBrowserDialog1.SelectedPath;
                this.LalbelSelectedPath.Text = this.FolderPath;

            }
        }
    }
}
